﻿using Crocodile.AbstractLanguage.Tree;
using JetBrains.Annotations;



namespace Crocodile.CsharpLanguage.Tree
{
    /// <summary>
    /// C# named entity.
    /// </summary>
    public class CsEntity : AbstractNode
    {

        /// <summary>
        /// C# class name.
        /// </summary>
        [NotNull]
        public string Name = "UnnamedClass";

        /// <summary>
        /// Visibility.
        /// Null means use parent visibility.
        /// </summary>
        public CsVisibility? Visibility;


        /// <summary>
        /// Actual visibility.
        /// </summary>
        public CsVisibility ActualVisibility()
        {
            if (Visibility != null)
            {
                return Visibility.Value;
            }
            else
            {
                var pe = ParentEntity;
                return pe ? pe.ActualVisibility() : CsVisibility.Internal;
            }
        }


        /// <summary>
        /// Parent if the parent is an entity, or null.
        /// </summary>
        [CanBeNull]
        public CsEntity ParentEntity { get { return Parent as CsEntity; } }

        /// <summary>
        /// Full name (with all namespace names, classes, etc.)
        /// </summary>
        public virtual string FullName
        {
            get
            {
                var pe = ParentEntity;
                return pe ? pe.FullName + '.' + Name : Name;
            }
        }


        /// <summary>
        /// Attributes.
        /// </summary>
        [NotNull]
        public readonly Nest<CsEntity,CsAttribute> Attributes;


        public CsEntity()
        {
            Attributes = new Nest<CsEntity,CsAttribute>(this);
        }


        public override string ToString()
        {
            return Name;
        }
    }
}
